#!/usr/bin/env python
#coding:utf-8

import urllib
from sgmllib import SGMLParser

class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.is_h1 = ''
        self.data = []

    def start_h1(self, tags):
        self.is_h1 = 1

    def end_h1(self):
        self.is_h1 = ''

    def handle_data(self, data):
        if self.is_h1:
            self.data.append(data)

p = URLLister()
#html = urllib.urlopen('http://www.google.com').read()
html = urllib.urlopen('tq.html').read()
data = p.feed(html)
p.close()
for d in p.data:
    print d

